﻿using DFGK_WMS.IRepository;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using NPOI.POIFS.Crypt.Dsig;
using NPOI.SS.Formula.Functions;

namespace DFGK_WMS.WebAPI
{
    public class OverallException : IAsyncExceptionFilter
    {
        private readonly ITLogRepository tLog;

        public OverallException(ITLogRepository tLog)
        {
            this.tLog = tLog;
        }
        ///全局异常处理
        public Task OnExceptionAsync(ExceptionContext context)
        {
            if (!context.ExceptionHandled)
            {
                //还没处理的异常进来

                //记录日志
                ApiResult result = new ApiResult();
                result.code = "500";
                result.message = "全局异常：" + context.Exception.Message;
                result.data = false;
                result.count = 0;
                context.Result = new JsonResult(result);

                context.ExceptionHandled = true;  //标注下当前这个异常已经处理过了
            }
            return Task.CompletedTask;
        }
    }
}
